package lab03.test07;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Test {
    public static void main(String[] args) {
//        7、	读取book.zip,并将book.zip中含有的文件重新存放到当前目录中的book文件夹中，
//        即将book.zip的内容解压到book文件夹中。

        //中文名称会报错
        String path = "D:\\book.zip";
//        File path1 = new File("D:\\");
        ZipInputStream zipInputStream = null;
        BufferedReader bufferedReader = null;
        BufferedWriter bufferedWriter = null;
        try {
            zipInputStream = new ZipInputStream(new FileInputStream(path));

            byte[] b = new byte[1024];
            //entry：压缩包中的信息
            ZipEntry entry;
            while ((entry = zipInputStream.getNextEntry()) != null) {
//                System.out.println(entry.getName());

//                File file=new File(path1,entry.getName());

                File file = new File("F:\\" + entry.getName()); // 获取文件目录
                System.out.println(file);
                if (!file.exists()) { // 如果该文件不存在
                    file.mkdirs();// 创建文件所在文件夹
                    file.createNewFile(); // 创建文件
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                zipInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
